package leetcode.code876.MiddleoftheLinkedList;

import leetcode.helper.tree.ListNode;

public class Solution1 extends MiddleoftheLinkedList {

	@Override
	public ListNode middleNode(ListNode head) {
		if (head.next == null)
			return head;
		ListNode fast = head;
		ListNode slow = head;
		while (fast.next != null) {
			if (fast.next.next != null) {
				fast = fast.next.next;
				slow = slow.next;
			} else {
				slow = slow.next;
				return slow;
			}
		}
		return slow;
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
//		so.debug1();
		so.debug2();
	}

}
